home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-21 | 7.2 KB | 319 lines | [TEXT/CWIE] |
- //===================================================================
- //======================= Headers =============================
-
- #include "ApplicationHandler.h"
- #include "ApplicationEvents.h"
- #include "MenuBar.h"
- #include "Screen.h"
-
- #include "BogusFinder.h"
- #include "BogusPhotoshop.h"
- #include "MacAmp.h"
- #include "BogusQuickTime.h"
-
- //===================================================================
- //======================= Globals =============================
-
- ApplicationHandler AH;
-
- //===================================================================
- //======================= #define =============================
-
-
- //===================================================================
- //======================= Function Prototypes =====================
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: Constructor
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandlerInit( void )
- {
- AH.LoadApplication( kFinderApp );
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: Constructor
-
- \----------------------------------------------------------------------------*/
- ApplicationHandler :: ApplicationHandler( void )
- : LinkListClass< Application >()
- {
- multApps = false;
- finder = NULL;
- action = 0;
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: HandleMouseClick
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandler :: HandleMouseClick( Boolean down, point where )
- {
- if( LastLink != NULL )
- {
- if( LastLink == finder )
- {
- finder->HandleMouseClick( down , where );
- }
- else if( !down )
- {
- LastLink->HandleMouseClick( down , where );
- }
- else
- if( !LastLink->HandleMouseClick( down , where ) )
- {
- // ifthe front app does not hadnle it go through the app
- // list untill something is hit
- Application *link = FirstLink;
-
- if( link == LastLink )
- link = link->next;
-
- while( link != NULL )
- {
- if( link->HandleMouseClick( down , where ) )
- {
- MakeFrontApp( link );
- return;
- }
-
- link = link->next;
-
- if( link == LastLink )
- link = NULL;
- }
- // nothing hit then go to the bogus finder
-
- if( down )
- {
- action |= 0x02;
- whichSwitch = finder;
- }
- }
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: HandleMouseMove
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandler :: HandleMouseMove( point where )
- {
- if( LastLink == finder )
- {
- finder->HandleMouseMove( where );
- }
- else
- LastLink->HandleMouseMove( where );
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: CleanUp
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandler :: CleanUp( rect *where )
- {
- Application *link = FirstLink;
-
- if( finder != NULL && LastLink != finder )
- {
- finder->CleanUp( where );
-
- if( link == finder )
- link = link->next;
- }
-
- while( link != NULL )
- {
- link->CleanUp( where );
-
- link = link->next;
-
- if( link == finder )
- link = link->next;
- }
-
- if( LastLink == finder )
- {
- finder->CleanUp( where );
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: Maintance
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandler :: Maintance( void )
- {
- // see if it needs to switch apps
- if( action & 0x01)
- RealLoadApp( whichLoad );
-
- if( action & 0x02 )
- MakeFrontApp( whichSwitch );
-
- action = 0;
-
- // do app maintance
-
- Application *link = FirstLink;
-
- while( link != NULL )
- {
- link->Maintance();
- link = link->next;
- }
-
-
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: LoadApplication
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandler :: LoadApplication( uchar what )
- {
- action |= 0x01;
- whichLoad = what;
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: RealLoadApp
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandler :: RealLoadApp( uchar what )
- {
- Application *link;
-
- link = NewApp( what );
- AddToList( link );
-
- MakeFrontApp( link );
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: LoadMultipleApps
-
- \----------------------------------------------------------------------------*/
- Boolean ApplicationHandler :: LoadMultipleApps( Boolean what )
- {
- multApps = what;
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: SendEventToCurrentApp
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandler :: SendEventToCurrentApp( ushort event , void *data )
- {
- // if it is a menu select intersept it and see if it should be sent
- // to the menu bar
- if( event == kAEMenuSelect )
- {
- if( ((AEMenuWhere *)data)->which == kAppleMenuTitle ||
- ((AEMenuWhere *)data)->which == kAppListMenuTitle )
- {
- menuBar.HandleSpecialMenuSelect( ((AEMenuWhere *)data)->which ,
- ((AEMenuWhere *)data)->num );
- return;
- }
- }
- LastLink->HandleEvent( event , data );
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: NewApp
-
- \----------------------------------------------------------------------------*/
- Application *ApplicationHandler :: NewApp( uchar what )
- {
- Application *temp = NULL;
-
- switch( what )
- {
- case kFinderApp:
- temp = new BogusFinder;
- ((BogusFinder *)temp)->Init();
-
- finder = temp;
- break;
-
- case kPhotoshopApp:
- temp = new BogusPhotoshop;
- ((BogusPhotoshop *)temp)->Init();
- break;
-
- case kMacAmp:
- temp = new MacAmp;
- ((MacAmp *)temp)->Init();
- break;
-
- case kQuickTime:
- temp = new BogusQuickTime;
- ((BogusQuickTime *)temp)->Init();
- break;
- }
-
- return temp;
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: MakeFrontApp
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandler :: MakeFrontApp( Application *app )
- {
- if( LastLink != NULL )
- LastLink->HandleEvent( kAEGoBackGroundEvent , NULL );
-
- menuBar.ClearMenuList();
-
- app->HandleEvent( kAEMakeFrontAppEvent , NULL );
-
- MoveAfter( LastLink , app );
-
- screen.DrawAll();
-
- Application *temp;
-
- for( temp = LastLink ; temp != NULL ; temp = temp->previous )
- menuBar.AddAppToList( temp->GetAppType() );
- }
-
- /*----------------------------------------------------------------------------\
-
- ApplicationHandler :: MakeFrontApp
-
- \----------------------------------------------------------------------------*/
- void ApplicationHandler :: SwitchToAppByNum( uchar num )
- {
- Application *temp;
- uchar i = 0;
-
- for( temp = LastLink ; temp != NULL ; temp = temp->previous )
- {
- if( num == i )
- {
- if( temp == LastLink )
- return;
-
- action |= 0x02;
- whichSwitch = temp;
- return;
- }
- i++;
- }
- }